package Thread_;

/*
* 线程优先级
* 1、优先级分为1~10级
* MAX_PRIORITY 相当于10
* MIN_PRIORITY      1
* NORM_PRIORITY     5
* 2、如何设置优先级
* 通过getPriority():获取线程的优先级
* 通过setPriority(int p):设置线程的优先级
* 3、高优先级的线程抢占cup执行权的概率会比较高，但是并不是高优先级的线程先执行完才轮到低优先级的执行
* */
public class ThreadPriority_ extends Thread {
    @Override
    public void run() {
        for (int i = 0; i <100 ; i++) {
            System.out.println("1-高优先级的线程");
        }
    }
}
class ThreadPriority1_ extends Thread {
    @Override
    public void run() {
        for (int i = 0; i <100 ; i++) {
            System.out.println("2-低优先级的线程");
        }
    }
}
class TestThreadPriority_ {
    public static void main(String[] args) {
        ThreadPriority_ threadPriority = new ThreadPriority_();
        threadPriority.setPriority(Thread.MAX_PRIORITY);
        threadPriority.start();

        ThreadPriority1_ threadPriority1 = new ThreadPriority1_();
        threadPriority1.setPriority(5);
        threadPriority1.start();
        for (int i = 0; i <100 ; i++) {
            System.out.println("主线程");
        }
    }
}